{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MIT-BIH"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train Data Shape:\n",
      "(87553, 188)\n",
      "Train Data Info:\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 87553 entries, 0 to 87552\n",
      "Columns: 188 entries, 9.779411554336547852e-01 to 0.000000000000000000e+00.88\n",
      "dtypes: float64(188)\n",
      "memory usage: 125.6 MB\n",
      "None\n",
      "\n",
      "Train Data Description:\n",
      "       9.779411554336547852e-01  9.264705777168273926e-01  \\\n",
      "count              87553.000000              87553.000000   \n",
      "mean                   0.890359                  0.758158   \n",
      "std                    0.240910                  0.221814   \n",
      "min                    0.000000                  0.000000   \n",
      "25%                    0.921922                  0.682482   \n",
      "50%                    0.991342                  0.826007   \n",
      "75%                    1.000000                  0.910506   \n",
      "max                    1.000000                  1.000000   \n",
      "\n",
      "       6.813725233078002930e-01  2.450980395078659058e-01  \\\n",
      "count              87553.000000              87553.000000   \n",
      "mean                   0.423969                  0.219104   \n",
      "std                    0.227305                  0.206880   \n",
      "min                    0.000000                  0.000000   \n",
      "25%                    0.250965                  0.048458   \n",
      "50%                    0.429467                  0.165992   \n",
      "75%                    0.578767                  0.341727   \n",
      "max                    1.000000                  1.000000   \n",
      "\n",
      "       1.544117629528045654e-01  1.911764740943908691e-01  \\\n",
      "count              87553.000000              87553.000000   \n",
      "mean                   0.201127                  0.210399   \n",
      "std                    0.177058                  0.171910   \n",
      "min                    0.000000                  0.000000   \n",
      "25%                    0.082329                  0.088415   \n",
      "50%                    0.147870                  0.158798   \n",
      "75%                    0.258993                  0.287634   \n",
      "max                    1.000000                  1.000000   \n",
      "\n",
      "       1.519607901573181152e-01  8.578431606292724609e-02  \\\n",
      "count              87553.000000              87553.000000   \n",
      "mean                   0.205809                  0.201774   \n",
      "std                    0.178482                  0.177241   \n",
      "min                    0.000000                  0.000000   \n",
      "25%                    0.073333                  0.066116   \n",
      "50%                    0.145320                  0.144424   \n",
      "75%                    0.298246                  0.295393   \n",
      "max                    1.000000                  1.000000   \n",
      "\n",
      "       5.882352963089942932e-02  4.901960864663124084e-02  ...  \\\n",
      "count              87553.000000              87553.000000  ...   \n",
      "mean                   0.198693                  0.196758  ...   \n",
      "std                    0.171778                  0.168358  ...   \n",
      "min                    0.000000                  0.000000  ...   \n",
      "25%                    0.065000                  0.068643  ...   \n",
      "50%                    0.150000                  0.148734  ...   \n",
      "75%                    0.290837                  0.283636  ...   \n",
      "max                    1.000000                  1.000000  ...   \n",
      "\n",
      "       0.000000000000000000e+00.79  0.000000000000000000e+00.80  \\\n",
      "count                 87553.000000                 87553.000000   \n",
      "mean                      0.005025                     0.004628   \n",
      "std                       0.044155                     0.042089   \n",
      "min                       0.000000                     0.000000   \n",
      "25%                       0.000000                     0.000000   \n",
      "50%                       0.000000                     0.000000   \n",
      "75%                       0.000000                     0.000000   \n",
      "max                       1.000000                     1.000000   \n",
      "\n",
      "       0.000000000000000000e+00.81  0.000000000000000000e+00.82  \\\n",
      "count                 87553.000000                 87553.000000   \n",
      "mean                      0.004291                     0.003945   \n",
      "std                       0.040525                     0.038651   \n",
      "min                       0.000000                     0.000000   \n",
      "25%                       0.000000                     0.000000   \n",
      "50%                       0.000000                     0.000000   \n",
      "75%                       0.000000                     0.000000   \n",
      "max                       1.000000                     1.000000   \n",
      "\n",
      "       0.000000000000000000e+00.83  0.000000000000000000e+00.84  \\\n",
      "count                 87553.000000                 87553.000000   \n",
      "mean                      0.003681                     0.003471   \n",
      "std                       0.037193                     0.036255   \n",
      "min                       0.000000                     0.000000   \n",
      "25%                       0.000000                     0.000000   \n",
      "50%                       0.000000                     0.000000   \n",
      "75%                       0.000000                     0.000000   \n",
      "max                       1.000000                     1.000000   \n",
      "\n",
      "       0.000000000000000000e+00.85  0.000000000000000000e+00.86  \\\n",
      "count                 87553.000000                 87553.000000   \n",
      "mean                      0.003221                     0.002945   \n",
      "std                       0.034790                     0.032865   \n",
      "min                       0.000000                     0.000000   \n",
      "25%                       0.000000                     0.000000   \n",
      "50%                       0.000000                     0.000000   \n",
      "75%                       0.000000                     0.000000   \n",
      "max                       1.000000                     1.000000   \n",
      "\n",
      "       0.000000000000000000e+00.87  0.000000000000000000e+00.88  \n",
      "count                 87553.000000                 87553.000000  \n",
      "mean                      0.002807                     0.473382  \n",
      "std                       0.031924                     1.143190  \n",
      "min                       0.000000                     0.000000  \n",
      "25%                       0.000000                     0.000000  \n",
      "50%                       0.000000                     0.000000  \n",
      "75%                       0.000000                     0.000000  \n",
      "max                       1.000000                     4.000000  \n",
      "\n",
      "[8 rows x 188 columns]\n",
      "Train Data Shape:\n",
      "(21891, 188)\n",
      "\n",
      "Test Data Info:\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 21891 entries, 0 to 21890\n",
      "Columns: 188 entries, 1.000000000000000000e+00 to 0.000000000000000000e+00.65\n",
      "dtypes: float64(188)\n",
      "memory usage: 31.4 MB\n",
      "None\n",
      "\n",
      "Test Data Description:\n",
      "       1.000000000000000000e+00  7.582644820213317871e-01  \\\n",
      "count              21891.000000              21891.000000   \n",
      "mean                   0.894405                  0.761902   \n",
      "std                    0.234564                  0.218664   \n",
      "min                    0.000000                  0.000000   \n",
      "25%                    0.924254                  0.683355   \n",
      "50%                    0.990431                  0.828996   \n",
      "75%                    1.000000                  0.912320   \n",
      "max                    1.000000                  1.000000   \n",
      "\n",
      "       1.115702465176582336e-01  0.000000000000000000e+00  \\\n",
      "count              21891.000000              21891.000000   \n",
      "mean                   0.426641                  0.221606   \n",
      "std                    0.228568                  0.208710   \n",
      "min                    0.000000                  0.000000   \n",
      "25%                    0.251220                  0.050514   \n",
      "50%                    0.432781                  0.167641   \n",
      "75%                    0.583994                  0.347097   \n",
      "max                    1.000000                  1.000000   \n",
      "\n",
      "       8.057851344347000122e-02  7.851240038871765137e-02  \\\n",
      "count              21891.000000              21891.000000   \n",
      "mean                   0.201682                  0.209897   \n",
      "std                    0.177730                  0.172195   \n",
      "min                    0.000000                  0.000000   \n",
      "25%                    0.082873                  0.087912   \n",
      "50%                    0.147651                  0.158120   \n",
      "75%                    0.259227                  0.287356   \n",
      "max                    1.000000                  1.000000   \n",
      "\n",
      "       6.611569970846176147e-02  4.958677664399147034e-02  \\\n",
      "count              21891.000000              21891.000000   \n",
      "mean                   0.204811                  0.200999   \n",
      "std                    0.177948                  0.176143   \n",
      "min                    0.000000                  0.000000   \n",
      "25%                    0.072678                  0.066003   \n",
      "50%                    0.144068                  0.144509   \n",
      "75%                    0.298456                  0.294566   \n",
      "max                    1.000000                  1.000000   \n",
      "\n",
      "       4.752065986394882202e-02  3.512396663427352905e-02  ...  \\\n",
      "count              21891.000000              21891.000000  ...   \n",
      "mean                   0.197640                  0.196030  ...   \n",
      "std                    0.170229                  0.166707  ...   \n",
      "min                    0.000000                  0.000000  ...   \n",
      "25%                    0.064516                  0.068506  ...   \n",
      "50%                    0.150442                  0.149038  ...   \n",
      "75%                    0.289907                  0.282966  ...   \n",
      "max                    1.000000                  0.991429  ...   \n",
      "\n",
      "       0.000000000000000000e+00.56  0.000000000000000000e+00.57  \\\n",
      "count                 21891.000000                 21891.000000   \n",
      "mean                      0.004588                     0.004328   \n",
      "std                       0.043129                     0.042188   \n",
      "min                       0.000000                     0.000000   \n",
      "25%                       0.000000                     0.000000   \n",
      "50%                       0.000000                     0.000000   \n",
      "75%                       0.000000                     0.000000   \n",
      "max                       0.980392                     1.000000   \n",
      "\n",
      "       0.000000000000000000e+00.58  0.000000000000000000e+00.59  \\\n",
      "count                 21891.000000                 21891.000000   \n",
      "mean                      0.004020                     0.003789   \n",
      "std                       0.040256                     0.039398   \n",
      "min                       0.000000                     0.000000   \n",
      "25%                       0.000000                     0.000000   \n",
      "50%                       0.000000                     0.000000   \n",
      "75%                       0.000000                     0.000000   \n",
      "max                       0.966102                     1.000000   \n",
      "\n",
      "       0.000000000000000000e+00.60  0.000000000000000000e+00.61  \\\n",
      "count                 21891.000000                 21891.000000   \n",
      "mean                      0.003639                     0.003459   \n",
      "std                       0.038536                     0.037718   \n",
      "min                       0.000000                     0.000000   \n",
      "25%                       0.000000                     0.000000   \n",
      "50%                       0.000000                     0.000000   \n",
      "75%                       0.000000                     0.000000   \n",
      "max                       1.000000                     1.000000   \n",
      "\n",
      "       0.000000000000000000e+00.62  0.000000000000000000e+00.63  \\\n",
      "count                 21891.000000                 21891.000000   \n",
      "mean                      0.003167                     0.003000   \n",
      "std                       0.035904                     0.035523   \n",
      "min                       0.000000                     0.000000   \n",
      "25%                       0.000000                     0.000000   \n",
      "50%                       0.000000                     0.000000   \n",
      "75%                       0.000000                     0.000000   \n",
      "max                       1.000000                     0.996053   \n",
      "\n",
      "       0.000000000000000000e+00.64  0.000000000000000000e+00.65  \n",
      "count                 21891.000000                 21891.000000  \n",
      "mean                      0.002946                     0.473711  \n",
      "std                       0.035267                     1.143469  \n",
      "min                       0.000000                     0.000000  \n",
      "25%                       0.000000                     0.000000  \n",
      "50%                       0.000000                     0.000000  \n",
      "75%                       0.000000                     0.000000  \n",
      "max                       1.000000                     4.000000  \n",
      "\n",
      "[8 rows x 188 columns]\n"
     ]
    }
   ],
   "source": [
    "# Загрузка данных\n",
    "train_df = pd.read_csv('datasets/mit-bih/mitbih_train.csv')\n",
    "test_df = pd.read_csv('datasets/mit-bih/mitbih_test.csv')\n",
    "\n",
    "# Вывод основных сведений о данных\n",
    "print(\"Train Data Shape:\")\n",
    "print(train_df.shape)\n",
    "print(\"Train Data Info:\")\n",
    "print(train_df.info())\n",
    "print(\"\\nTrain Data Description:\")\n",
    "print(train_df.describe())\n",
    "\n",
    "print(\"Train Data Shape:\")\n",
    "print(test_df.shape)\n",
    "print(\"\\nTest Data Info:\")\n",
    "print(test_df.info())\n",
    "print(\"\\nTest Data Description:\")\n",
    "print(test_df.describe())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "First 5 rows of Train Data:\n",
      "   9.779411554336547852e-01  9.264705777168273926e-01  \\\n",
      "0                  0.960114                  0.863248   \n",
      "1                  1.000000                  0.659459   \n",
      "2                  0.925414                  0.665746   \n",
      "3                  0.967136                  1.000000   \n",
      "4                  0.927461                  1.000000   \n",
      "\n",
      "   6.813725233078002930e-01  2.450980395078659058e-01  \\\n",
      "0                  0.461538                  0.196581   \n",
      "1                  0.186486                  0.070270   \n",
      "2                  0.541436                  0.276243   \n",
      "3                  0.830986                  0.586854   \n",
      "4                  0.626943                  0.193437   \n",
      "\n",
      "   1.544117629528045654e-01  1.911764740943908691e-01  \\\n",
      "0                  0.094017                  0.125356   \n",
      "1                  0.070270                  0.059459   \n",
      "2                  0.196133                  0.077348   \n",
      "3                  0.356808                  0.248826   \n",
      "4                  0.094991                  0.072539   \n",
      "\n",
      "   1.519607901573181152e-01  8.578431606292724609e-02  \\\n",
      "0                  0.099715                  0.088319   \n",
      "1                  0.056757                  0.043243   \n",
      "2                  0.071823                  0.060773   \n",
      "3                  0.145540                  0.089202   \n",
      "4                  0.043178                  0.053541   \n",
      "\n",
      "   5.882352963089942932e-02  4.901960864663124084e-02  ...  \\\n",
      "0                  0.074074                  0.082621  ...   \n",
      "1                  0.054054                  0.045946  ...   \n",
      "2                  0.066298                  0.058011  ...   \n",
      "3                  0.117371                  0.150235  ...   \n",
      "4                  0.093264                  0.189983  ...   \n",
      "\n",
      "   0.000000000000000000e+00.79  0.000000000000000000e+00.80  \\\n",
      "0                          0.0                          0.0   \n",
      "1                          0.0                          0.0   \n",
      "2                          0.0                          0.0   \n",
      "3                          0.0                          0.0   \n",
      "4                          0.0                          0.0   \n",
      "\n",
      "   0.000000000000000000e+00.81  0.000000000000000000e+00.82  \\\n",
      "0                          0.0                          0.0   \n",
      "1                          0.0                          0.0   \n",
      "2                          0.0                          0.0   \n",
      "3                          0.0                          0.0   \n",
      "4                          0.0                          0.0   \n",
      "\n",
      "   0.000000000000000000e+00.83  0.000000000000000000e+00.84  \\\n",
      "0                          0.0                          0.0   \n",
      "1                          0.0                          0.0   \n",
      "2                          0.0                          0.0   \n",
      "3                          0.0                          0.0   \n",
      "4                          0.0                          0.0   \n",
      "\n",
      "   0.000000000000000000e+00.85  0.000000000000000000e+00.86  \\\n",
      "0                          0.0                          0.0   \n",
      "1                          0.0                          0.0   \n",
      "2                          0.0                          0.0   \n",
      "3                          0.0                          0.0   \n",
      "4                          0.0                          0.0   \n",
      "\n",
      "   0.000000000000000000e+00.87  0.000000000000000000e+00.88  \n",
      "0                          0.0                          0.0  \n",
      "1                          0.0                          0.0  \n",
      "2                          0.0                          0.0  \n",
      "3                          0.0                          0.0  \n",
      "4                          0.0                          0.0  \n",
      "\n",
      "[5 rows x 188 columns]\n"
     ]
    }
   ],
   "source": [
    "print(\"\\nFirst 5 rows of Train Data:\")\n",
    "print(train_df.head())\n",
    "\n",
    "# print(\"\\nFirst 5 rows of Test Data:\")\n",
    "# print(test_df.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.779411554336547852e-01       0.960114\n",
       "9.264705777168273926e-01       0.863248\n",
       "6.813725233078002930e-01       0.461538\n",
       "2.450980395078659058e-01       0.196581\n",
       "1.544117629528045654e-01       0.094017\n",
       "                                 ...   \n",
       "0.000000000000000000e+00.84    0.000000\n",
       "0.000000000000000000e+00.85    0.000000\n",
       "0.000000000000000000e+00.86    0.000000\n",
       "0.000000000000000000e+00.87    0.000000\n",
       "0.000000000000000000e+00.88    0.000000\n",
       "Name: 0, Length: 188, dtype: float64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(train_df.loc[0])\n",
    "train_df.loc[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ECG"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train Data Keys: dict_keys(['samples', 'labels'])\n",
      "Validation Data Keys: dict_keys(['samples', 'labels'])\n",
      "Test Data Keys: dict_keys(['samples', 'labels'])\n",
      "\n",
      "Train Samples Shape: torch.Size([43673, 1, 1500])\n",
      "Validation Samples Shape: torch.Size([10920, 1, 1500])\n",
      "Test Samples Shape: torch.Size([1904, 1, 1500])\n",
      "\n",
      "Train Labels Shape: torch.Size([43673])\n",
      "Validation Labels Shape: torch.Size([10920])\n",
      "Test Labels Shape: torch.Size([1904])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "# Загрузка данных\n",
    "train_data = torch.load('datasets/ECG/train.pt')\n",
    "valid_data = torch.load('datasets/ECG/val.pt')\n",
    "test_data = torch.load('datasets/ECG/test.pt')\n",
    "\n",
    "# Проверка ключей и структуры данных\n",
    "print(\"Train Data Keys:\", train_data.keys())\n",
    "print(\"Validation Data Keys:\", valid_data.keys())\n",
    "print(\"Test Data Keys:\", test_data.keys())\n",
    "print()\n",
    "\n",
    "# Предположим, что данные находятся под ключом 'data'\n",
    "print(\"Train Samples Shape:\", train_data['samples'].shape)\n",
    "print(\"Validation Samples Shape:\", valid_data['samples'].shape)\n",
    "print(\"Test Samples Shape:\", test_data['samples'].shape)\n",
    "print()\n",
    "\n",
    "# Предположим, что данные находятся под ключом 'data'\n",
    "print(\"Train Labels Shape:\", train_data['labels'].shape)\n",
    "print(\"Validation Labels Shape:\", valid_data['labels'].shape)\n",
    "print(\"Test Labels Shape:\", test_data['labels'].shape)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train Data Keys: dict_keys(['samples', 'labels'])\n",
      "Validation Data Keys: dict_keys(['samples', 'labels'])\n",
      "Test Data Keys: dict_keys(['samples', 'labels'])\n",
      "\n",
      "Train Samples Shape: torch.Size([122, 1, 1500])\n",
      "Validation Samples Shape: torch.Size([41, 1, 1500])\n",
      "Test Samples Shape: torch.Size([41, 1, 1500])\n",
      "\n",
      "Train Labels Shape: torch.Size([122])\n",
      "Validation Labels Shape: torch.Size([41])\n",
      "Test Labels Shape: torch.Size([41])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "# Загрузка данных\n",
    "train_data = torch.load('datasets/EMG/train.pt')\n",
    "valid_data = torch.load('datasets/EMG/val.pt')\n",
    "test_data = torch.load('datasets/EMG/test.pt')\n",
    "\n",
    "# Проверка ключей и структуры данных\n",
    "print(\"Train Data Keys:\", train_data.keys())\n",
    "print(\"Validation Data Keys:\", valid_data.keys())\n",
    "print(\"Test Data Keys:\", test_data.keys())\n",
    "print()\n",
    "\n",
    "# Предположим, что данные находятся под ключом 'data'\n",
    "print(\"Train Samples Shape:\", train_data['samples'].shape)\n",
    "print(\"Validation Samples Shape:\", valid_data['samples'].shape)\n",
    "print(\"Test Samples Shape:\", test_data['samples'].shape)\n",
    "print()\n",
    "\n",
    "# Предположим, что данные находятся под ключом 'data'\n",
    "print(\"Train Labels Shape:\", train_data['labels'].shape)\n",
    "print(\"Validation Labels Shape:\", valid_data['labels'].shape)\n",
    "print(\"Test Labels Shape:\", test_data['labels'].shape)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-19 19:26:17,722 - INFO - Получение списка файлов .npy...\n",
      "2024-06-19 19:26:17,765 - INFO - Загрузка и объединение данных...\n",
      "100%|██████████| 20985/20985 [00:05<00:00, 3691.69it/s]\n",
      "2024-06-19 19:26:26,377 - INFO - Разделение данных на выборки...\n",
      "2024-06-19 19:26:31,677 - INFO - Преобразование данных в тензоры PyTorch...\n",
      "2024-06-19 19:26:31,705 - INFO - Сохранение выборок в формате .pt...\n",
      "2024-06-19 19:26:33,270 - INFO - Процесс завершен.\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "import torch\n",
    "from sklearn.model_selection import train_test_split\n",
    "from tqdm import tqdm\n",
    "import logging\n",
    "\n",
    "logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')\n",
    "\n",
    "data_dir = \"./datasets/ptb-xl/ptbxl_data_signals100\"\n",
    "\n",
    "logging.info(\"Получение списка файлов .npy...\")\n",
    "npy_files = [os.path.join(data_dir, f) for f in os.listdir(data_dir) if f.endswith(\".npy\")]\n",
    "\n",
    "logging.info(\"Загрузка и объединение данных...\")\n",
    "all_data = np.concatenate([np.load(f) for f in tqdm(npy_files)], axis=0)\n",
    "\n",
    "logging.info(\"Разделение данных на выборки...\")\n",
    "train_data, val_and_test_data = train_test_split(all_data, test_size=0.4, random_state=42)\n",
    "val_data, test_data = train_test_split(val_and_test_data, test_size=0.5, random_state=42)\n",
    "\n",
    "logging.info(\"Преобразование данных в тензоры PyTorch...\")\n",
    "train_data = torch.from_numpy(train_data)\n",
    "val_data = torch.from_numpy(val_data)\n",
    "test_data = torch.from_numpy(test_data)\n",
    "\n",
    "logging.info(\"Сохранение выборок в формате .pt...\")\n",
    "torch.save(train_data, \"train.pt\")\n",
    "torch.save(val_data, \"val.pt\")\n",
    "torch.save(test_data, \"test.pt\")\n",
    "\n",
    "logging.info(\"Процесс завершен.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-19 19:40:51,342 - INFO - Загрузка CSV-файлов...\n",
      "2024-06-19 19:40:55,926 - INFO - Разделение тренировочной выборки на тренировочную и валидационную...\n",
      "2024-06-19 19:40:56,188 - INFO - Преобразование данных в тензоры PyTorch...\n",
      "2024-06-19 19:40:56,274 - INFO - Сохранение выборок в формате .pt...\n",
      "2024-06-19 19:40:56,422 - INFO - Процесс завершен.\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "import torch\n",
    "from tqdm import tqdm\n",
    "import logging\n",
    "\n",
    "logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')\n",
    "\n",
    "data_dir = \"./datasets/mit-bih\"\n",
    "\n",
    "logging.info(\"Загрузка CSV-файлов...\")\n",
    "mitbih_train = pd.read_csv(os.path.join(data_dir, \"mitbih_train.csv\"))\n",
    "mitbih_test = pd.read_csv(os.path.join(data_dir, \"mitbih_test.csv\"))\n",
    "\n",
    "logging.info(\"Разделение тренировочной выборки на тренировочную и валидационную...\")\n",
    "train_data, val_data = train_test_split(mitbih_train, test_size=0.25, random_state=42)\n",
    "\n",
    "logging.info(\"Преобразование данных в тензоры PyTorch...\")\n",
    "train_data = torch.from_numpy(train_data.values).float()\n",
    "val_data = torch.from_numpy(val_data.values).float()\n",
    "test_data = torch.from_numpy(mitbih_test.values).float()\n",
    "\n",
    "logging.info(\"Сохранение выборок в формате .pt...\")\n",
    "torch.save(train_data, \"train.pt\")\n",
    "torch.save(val_data, \"val.pt\")\n",
    "torch.save(test_data, \"test.pt\")\n",
    "\n",
    "logging.info(\"Процесс завершен.\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
